package pl.gpms.server.persistance.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pl.gpms.client.dto.SymptomDictDTO;
import pl.gpms.server.persistance.map.SymptomDict;
import pl.gpms.server.persistance.tools.HibernateUtil;

public class SymptomDictDao {
	
	@SuppressWarnings("unchecked")
	public static List<String> getSymptomsList() {
		
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		List<String> symptomsNames = null;
		List<SymptomDict> symptomList = null;
		
		
		try {
			transaction = session.beginTransaction();
			symptomList = (ArrayList<SymptomDict>) session.createQuery("from SymptomDict").list();
		} catch( HibernateException e ) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		
		if( symptomList != null ) {
			symptomsNames = new ArrayList<String>();
			for(SymptomDict symList : symptomList) {
				symptomsNames.add(symList.getSymptomName());
			}
		}
		
		return symptomsNames;
	}
	
	public SymptomDictDTO createSymptomDictDTO( SymptomDict symptomDict ) {
		return new SymptomDictDTO( symptomDict.getSymptomName() );
	}
}
